package com.jxc.jxc01.grc.web;

import com.jxc.jxc01.grc.entity.Manifest;
import com.jxc.jxc01.grc.entity.Return;
import com.jxc.jxc01.grc.service.IReturnService;
import com.jxc.jxc01.grc.service.impl.IReturnServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(value = "/addreturn")
public class AddReturnServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request,
                           HttpServletResponse response)
            throws ServletException, IOException {
        IReturnService returnService = new IReturnServiceImpl();
        request.setCharacterEncoding("utf-8"); 
        response.setContentType("text/html;charset=utf-8");
        System.out.println("addreturn");

        int procurement = Integer.parseInt(request.getParameter("procurement"));
        int chargebacks = Integer.parseInt(request.getParameter("chargebacks"));
        int quantity = Integer.parseInt(request.getParameter("quantity"));
        double unit_price = Double.parseDouble(request.getParameter("unit_price"));
        double price = Double.parseDouble(request.getParameter("price"));
        String state = request.getParameter("states");
        String return_time = request.getParameter("return_time");
        String cause = request.getParameter("cause");

        Return returnModel = new Return();
        returnModel.setProcurement(procurement);
        returnModel.setChargebacks(chargebacks);
        returnModel.setQuantity(quantity);
        returnModel.setUnit_price(unit_price);
        returnModel.setPrice(price);
        returnModel.setState(state);
        returnModel.setReturn_time(return_time);
        returnModel.setCause(cause);

        boolean b = returnService.addOneOfReturn(returnModel);
        if (b){
            System.out.println("添加 成功");
        }else {
            response.sendRedirect("添加失败");
        }
    }
}
